#!/usr/bin/env python
# -*- coding:utf-8 -*-
# @FileName  :keywords.py
# @Time      :2023/6/27 
# @Author    :CL
# @email     :1037654919@qq.com
#  构造专门用于图片搜索的关键词库 , 关键词库中包含英文关键词和对应的中文关键词，以中文关键词作为关键词库的索引（主键）
import time

from fanyi import fanyi

key_words = [
    {"en_key": "Car design ", "zh_key": "汽车设计"},
    {"en_key": "Automotive concepts ", "zh_key": "汽车概念"},
    {"en_key": "Automotive concepts ", "zh_key": "汽车概念"},
    {"en_key": "Vehicle sketches ", "zh_key": "汽车草图"},
    {"en_key": "Automobile blueprints ", "zh_key": "汽车蓝图"},
    {"en_key": "Conceptual car drawings ", "zh_key": "概念汽车绘画"},
    {"en_key": "Automotive styling ", "zh_key": "汽车造型设计"},
    {"en_key": "Car rendering ", "zh_key": "汽车渲染"},
    {"en_key": "Automotive sketches ", "zh_key": "汽车草图"},
    {"en_key": "Vehicle concepts ", "zh_key": "汽车概念"},
    {"en_key": "Car concept art ", "zh_key": "汽车概念艺术"},
    {"en_key": "Automotive illustrations ", "zh_key": "汽车插图"},
    {"en_key": "Automobile design sketches ", "zh_key": "汽车设计草图"},
    {"en_key": "Vehicle prototypes ", "zh_key": " 汽车原型"},
    {"en_key": "Car concept sketches ", "zh_key": "汽车概念草图"},
    {"en_key": "Automotive renderings ", "zh_key": "汽车渲染图"},
    {"en_key": "Automobile concept art ", "zh_key": "汽车概念艺术"},
    {"en_key": "Vehicle design ideas ", "zh_key": "汽车设计创意"},
    {"en_key": "Car design inspiration ", "zh_key": "汽车设计灵感"},
    {"en_key": "Automotive concept sketches ", "zh_key": "汽车概念草图"},
    {"en_key": "Automobile prototype designs ", "zh_key": "汽车原型设计"},
    {"en_key": "Vehicle concept illustrations ", "zh_key": "汽车概念插图"},
    {"en_key": "Car design concepts ", "zh_key": "汽车设计概念"},
    {"en_key": "Automotive design sketches ", "zh_key": "汽车设计草图"},
    {"en_key": "Automobile concept renderings ", "zh_key": "汽车概念渲染图"},
    {"en_key": "Vehicle styling ideas ", "zh_key": " 汽车造型创意"},
    {"en_key": "Car design sketches ", "zh_key": " 汽车设计草图"},
    {"en_key": "Automotive concept art ", "zh_key": " 汽车概念艺术"},
    {"en_key": "Automobile design concepts ", "zh_key": " 汽车设计概念"},
    {"en_key": "Vehicle concept designs ", "zh_key": " 汽车概念设计"},
    {"en_key": "Car rendering techniques ", "zh_key": " 汽车渲染技术"},
    {"en_key": "Automotive sketching tips ", "zh_key": " 汽车草图绘制技巧"},
    {"en_key": "Automobile concept sketches ", "zh_key": " 汽车概念草图"},
    {"en_key": "Vehicle design inspiration ", "zh_key": " 汽车设计灵感"},
    {"en_key": "Car design process ", "zh_key": " 汽车设计过程"},
    {"en_key": "Automotive concept renderings ", "zh_key": " 汽车概念渲染图"},
    {"en_key": "Automobile styling ideas ", "zh_key": " 汽车造型创意"},
    {"en_key": "Vehicle rendering techniques ", "zh_key": " 汽车渲染技术"},
    {"en_key": "Car design trends ", "zh_key": " 汽车设计趋势"},
    {"en_key": "Automotive sketching tutorials ", "zh_key": " 汽车草图绘制教程"},
    {"en_key": "Automobile concept designs ", "zh_key": " 汽车概念设计"}]
from utils import mongo_manager

sucai_title_code = mongo_manager("sucai_title_code", db='car_images')
sucai_image = mongo_manager("sucai_image", db='car_images')
images_keywords = mongo_manager("images_keywords", db='car_images')
stocksnap_categories = mongo_manager("stocksnap_categories", db='car_images')


# 增加第一批关键词
def add_1():
    # print(keywords_from_sucai)
    seeds = sucai_title_code.findAll()
    for seed in seeds:
        code2 = str(seed['href']).split('_')[-1].split('.')[0]
        if code2 == '0':  # 跳过大类，避免重复
            continue
        keyword = str(seed['title']).replace('图片', '').replace('其他', '')
        print(keyword)
        if keyword:
            result = {'_id': keyword, 'keyword': keyword}
            # 检查并添加 'title_en' 字段 'hippopx' 字段 file_count' 字段  pinterest' 字段
            if 'title_en' in seed and seed['title_en']:
                result['keyword_en'] = seed['title_en']
            if 'hippopx' in seed and seed['hippopx']:
                result['hippopx'] = seed['hippopx']
            if 'file_count' in seed:
                result['hippopx_count'] = seed['file_count']
            if 'pinterest' in seed and seed['pinterest']:
                result['pinterest'] = seed['pinterest']
            try:
                images_keywords.insertOne(result)
            except Exception as e:
                print(e)


# 增加第二批关键词
def add_2():
    seeds = stocksnap_categories.findAll()
    for seed in seeds:
        keyword_en = seed['keyword']
        keyword = fanyi(keyword_en, _from='en', _to='zh')
        if keyword:
            result = {'_id': keyword, 'keyword': keyword, 'keyword_en': keyword_en}
            try:
                images_keywords.insertOne(result)
            except Exception as e:
                print(e)
        time.sleep(3)


# 增加第三批关键词
def add_3():
    keywords1 = [
        "人体摄影",
        "手势",
        "婚纱",
        "情侣",
        "人物速写",
        "帅哥",
        "性感美女",
        "发型",
        "商务人物",
        "短发发型",
        "古典美女",
        "办公人物",
        "功夫手势",
        "和服美女",
        "梨花头",
        "持枪动作",
        "家庭",
        "男人",
        "女人",
        "艺术写真",
        "校园生活",
        "插画",
        "儿童玩耍",
        "工作场景",
        "交通工具",
        "户外风景",
        "城市建筑",
        "山水风光",
        "星空银河",
        "科技创新",
        "医疗护理",
        "农业生产",
        "动物世界",
        "自然生态",
        "美食料理",
        "时尚穿搭",
        "健身健美",
        "宠物萌宠",
        "婴儿育儿",
        "旅行度假",
        "音乐表演",
        "舞蹈艺术",
        "体育运动",
        "传统节日",
        "文化艺术",
        "科学探索",
        "历史遗迹",
        "军事战争"
    ]
    keywords2 = [
        "人像",
        "动作",
        "风景",
        "运动",
        "艺术",
        "卡通",
        "自然",
        "科技",
        "建筑",
        "创意",
        "时尚",
        "旅行",
        "音乐",
        "舞蹈",
        "体育",
        "节日",
        "文化",
        "历史",
        "军事",
        "电影",
        "电视",
        "摄影",
        "绘画",
        "设计",
        "模特",
        "明星",
        "海滩",
        "山川",
        "湖泊",
        "河流",
        "森林",
        "植物",
        "动物",
        "鸟类",
        "昆虫",
        "海洋",
        "太空",
        "宇宙",
        "人工智能",
        "机器人",
        "医疗",
        "健康",
        "农业",
        "汽车",
        "飞机",
        "火车",
        "船舶",
        "手机",
        "电脑",
        "游戏",
        "美食",
        "烹饪",
        "健身",
        "瑜伽",
        "宠物",
        "猫狗",
        "婴儿",
        "孩子",
        "教育",
        "学校",
        "大学",
        "工作",
        "职业",
        "金融",
        "商务",
        "电子商务",
        "市场营销",
        "社交媒体",
        "互联网",
        "搜索引擎",
        "数据分析",
        "人工智能",
        "区块链",
        "虚拟现实",
        "物联网",
        "智能家居",
        "环境保护",
        "可持续发展",
        "传统文化",
        "民族音乐",
        "戏剧表演",
        "世界遗产",
        "军事历史",
        "战争纪实",
        "科学研究",
        "空间探索",
        "人类进化",
        "心理学",
        "社会学",
        "哲学思考"
    ]
    keywords = keywords1 + keywords2
    for keyword in keywords:
        if images_keywords.not_exist({'_id': keyword}):
            keyword_en = fanyi(keyword, _from='zh', _to='en')
            time.sleep(3)
            result = {'_id': keyword, 'keyword': keyword}
            if keyword_en:
                result['keyword_en'] = keyword_en
            try:
                images_keywords.insertOne(result)
            except Exception as e:
                print(e)
def add_4():
    keywords = ['cardesign', 'concept car', 'futuristic car', 'conceptcar', 'car',
            'sportscar', 'supercar',
            'Automotive', 'super car',
            'fantastic car', 'amazing car',
            'vehicle car', 'vehicle',
            'wonderful car', 'beautiful car',
            ]
    for keyword_en in keywords:
        keyword = fanyi(keyword_en, _from='en', _to='zh')
        time.sleep(3)
        if images_keywords.not_exist({'_id': keyword}):
            result = {'_id': keyword, 'keyword': keyword,'keyword_en': keyword_en}
            try:
                images_keywords.insertOne(result)
            except Exception as e:
                print(e)
def add_5():
    key_words = [
        {"en_key": "Car design ", "zh_key": "汽车设计"},
        {"en_key": "Automotive concepts ", "zh_key": "汽车概念"},
        {"en_key": "Automotive concepts ", "zh_key": "汽车概念"},
        {"en_key": "Vehicle sketches ", "zh_key": "汽车草图"},
        {"en_key": "Automobile blueprints ", "zh_key": "汽车蓝图"},
        {"en_key": "Conceptual car drawings ", "zh_key": "概念汽车绘画"},
        {"en_key": "Automotive styling ", "zh_key": "汽车造型设计"},
        {"en_key": "Car rendering ", "zh_key": "汽车渲染"},
        {"en_key": "Automotive sketches ", "zh_key": "汽车草图"},
        {"en_key": "Vehicle concepts ", "zh_key": "汽车概念"},
        {"en_key": "Car concept art ", "zh_key": "汽车概念艺术"},
        {"en_key": "Automotive illustrations ", "zh_key": "汽车插图"},
        {"en_key": "Automobile design sketches ", "zh_key": "汽车设计草图"},
        {"en_key": "Vehicle prototypes ", "zh_key": " 汽车原型"},
        {"en_key": "Car concept sketches ", "zh_key": "汽车概念草图"},
        {"en_key": "Automotive renderings ", "zh_key": "汽车渲染图"},
        {"en_key": "Automobile concept art ", "zh_key": "汽车概念艺术"},
        {"en_key": "Vehicle design ideas ", "zh_key": "汽车设计创意"},
        {"en_key": "Car design inspiration ", "zh_key": "汽车设计灵感"},
        {"en_key": "Automotive concept sketches ", "zh_key": "汽车概念草图"},
        {"en_key": "Automobile prototype designs ", "zh_key": "汽车原型设计"},
        {"en_key": "Vehicle concept illustrations ", "zh_key": "汽车概念插图"},
        {"en_key": "Car design concepts ", "zh_key": "汽车设计概念"},
        {"en_key": "Automotive design sketches ", "zh_key": "汽车设计草图"},
        {"en_key": "Automobile concept renderings ", "zh_key": "汽车概念渲染图"},
        {"en_key": "Vehicle styling ideas ", "zh_key": " 汽车造型创意"},
        {"en_key": "Car design sketches ", "zh_key": " 汽车设计草图"},
        {"en_key": "Automotive concept art ", "zh_key": " 汽车概念艺术"},
        {"en_key": "Automobile design concepts ", "zh_key": " 汽车设计概念"},
        {"en_key": "Vehicle concept designs ", "zh_key": " 汽车概念设计"},
        {"en_key": "Car rendering techniques ", "zh_key": " 汽车渲染技术"},
        {"en_key": "Automotive sketching tips ", "zh_key": " 汽车草图绘制技巧"},
        {"en_key": "Automobile concept sketches ", "zh_key": " 汽车概念草图"},
        {"en_key": "Vehicle design inspiration ", "zh_key": " 汽车设计灵感"},
        {"en_key": "Car design process ", "zh_key": " 汽车设计过程"},
        {"en_key": "Automotive concept renderings ", "zh_key": " 汽车概念渲染图"},
        {"en_key": "Automobile styling ideas ", "zh_key": " 汽车造型创意"},
        {"en_key": "Vehicle rendering techniques ", "zh_key": " 汽车渲染技术"},
        {"en_key": "Car design trends ", "zh_key": " 汽车设计趋势"},
        {"en_key": "Automotive sketching tutorials ", "zh_key": " 汽车草图绘制教程"},
        {"en_key": "Automobile concept designs ", "zh_key": " 汽车概念设计"}]
    for data in key_words:
        keyword = data['zh_key']
        keyword_en = data['en_key']
        try:
            images_keywords.insertOne({"_id": keyword, "keyword": keyword, "keyword_en": keyword_en})
        except Exception as e:
            print(e)
 # freejpg
def add_6():
    freejpg_categories = mongo_manager('freejpg_categories',db = 'car_images')
    seeds = freejpg_categories.findAll({"category": {"$exists":True}})
    for seed in seeds:
        keyword_en= seed['category']
        keyword = fanyi(keyword_en,_from='en',_to='zh')
        time.sleep(3)
        if keyword:
            try:
                images_keywords.insertOne({"_id": keyword, "keyword": keyword, "keyword_en": keyword_en,'freejpg':seed['status']})
            except Exception as e:
                images_keywords.updateOne({"_id": keyword},{"freejpg":seed['status']})

#  20240524 增加第七批关键词 停车场相关
def add_7():
    keywords = ['停车场二维码','停车场出入口','停车场出入口道闸','停车场入口二维码','停车场入口','停车场出口','停车场']
    for keyword in keywords:
        if images_keywords.not_exist({'_id': keyword}):
            keyword_en = fanyi(keyword, _from='zh', _to='en')
            time.sleep(3)
            result = {'_id': keyword, 'keyword': keyword}
            if keyword_en:
                result['keyword_en'] = keyword_en
            try:
                images_keywords.insertOne(result)
            except Exception as e:
                print(e)
        else:
            print(keyword, '已存在')

# 20241028 增加第八批关键词 人物相关
def add_8():
    keywords = [
        "车内中国婴儿", "中国婴儿宝宝照",
        "车内中国儿童男", "中国儿童男",
        "车内中国儿童女", "中国儿童女",
        "车内中国成年人男", "中国成年人男",
        "车内中国成年人女", "中国成年人女",
        "车内中国老年人男", "中国老年人男人像",
        "车内中国老年人女", "中国老年人女人像"
    ]
    for keyword in keywords:
        if images_keywords.not_exist({'_id': keyword}):
            keyword_en = fanyi(keyword, _from='zh', _to='en')
            time.sleep(3)
            result = {'_id': keyword, 'keyword': keyword,'_for':'person'}
            if keyword_en:
                result['keyword_en'] = keyword_en
            try:
                images_keywords.insertOne(result)
            except Exception as e:
                print(e)
        else:
            print(keyword, '已存在')
if __name__ == '__main__':
    print()
    add_8()

